home *** CD-ROM | disk | FTP | other *** search
/ Amoszine 11 / Amoszine 11 (Disk 2 of 2).adf / Ben_Wyatt_Source.lha / Directory_Deleter.AMOS / Directory_Deleter.amosSourceCode
AMOS Source Code  |  2004-04-12  |  1KB  |  46 lines

  1. ' Directory Deleter
  2. ' ~~~~~~~~~~~~~~~~~
  3. ' by Ben Wyatt, bwyatt@paston.co.uk
  4. '
  5. ' Deletes directories - simple as that 
  6.  
  7. F$=Fsel$("","LeaveMe","Go into directory to delete","and select 'Okay'")
  8. F$=F$-"LeaveMe"
  9. If F$<>"" : _DELETEDIR[F$] : End If 
  10. Edit 
  11.  
  12. Procedure _DELETEDIR[F$]
  13.  
  14.    ' Delete directory (F$=Directory to delete)
  15.  
  16.    ' Add "/" if nessassary
  17.    If Right$(F$,1)<>"/" : F$=F$+"/" : End If 
  18.  
  19.    ' Reserve an array to hold the filenames 
  20.    MXFILES=511
  21.    Dim FILE$(MXFILES)
  22.  
  23.    ' Goes through the directory and stores everything in the array
  24.    FILENUM=0 : D$=Dir First$(F$)
  25.    While D$<>""
  26.       ' Removes trailing spaces
  27.       X=29 : While Mid$(D$,X,1)=" " : Dec X : Wend 
  28.       FILE$(FILENUM)=Left$(D$,X) : Inc FILENUM
  29.       D$=Dir Next$
  30.    Wend 
  31.  
  32.    If FILENUM>0
  33.       ' Go through the directory array and delete everything 
  34.       ' If directory found, then it's deleted with this procedure recursively
  35.       For N=0 To FILENUM-1
  36.          D$=Right$(FILE$(N),Len(FILE$(N))-1)
  37.          If Left$(FILE$(N),1)="*" : _DELETEDIR[F$+D$]
  38.          Else Kill F$+D$
  39.          End If 
  40.       Next N
  41.    End If 
  42.  
  43.    ' Finally delete the actual directory  
  44.    Kill Left$(F$,Len(F$)-1)
  45.  
  46. End Proc